package qq2564874169.tuaotuao.fx.orm.mybatis;


import qq2564874169.tuaotuao.fx.orm.query.PageSet;

public class MysqlSql extends AbstractMybatisSql {
    public MysqlSql(MybatisContext context) {
        super(context);
    }

    @Override
    protected SqlPager getPager(PageSet pageSet) {
        return new SqlPager() {
            private PageSet ps = pageSet;

            @Override
            public String countSql(String sql) {
                return "select count(1) c from(" + sql + ") t";
            }

            @Override
            public String dataSql(String sql) {
                int start = (ps.pageIndex - 1) * ps.pageSize;
                return sql + " limit " + start + "," + ps.pageSize;
            }
        };
    }

    @Override
    public String escapeField(String field) {
        return "`" + field + "`";
    }
}
